/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lijiankun24.shadowlayoutexample;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;

/**
 * test
 *
 * @author rpf
 * @since 2021-05-25
 */
public class ExampleOhosTest {
    /**
     * 包名test
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.lijiankun24.shadowlayoutexample", actualBundleName);
    }

    /**
     * test加
     */
    @Test
    public void testAdd(){
        try {
            Class numberUtil = Class.forName("com.lijiankun24.shadowlayout.NumberUtil");
            Method add = numberUtil.getMethod("add", double.class, double.class);
            Object obj = numberUtil.getConstructor().newInstance();
            int invoke = (int) add.invoke(obj,1.0,1.0);
            assertEquals(2,invoke);
        } catch (InstantiationException | InvocationTargetException |
                NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * test减
     */
    @Test
    public void testSub(){
        try {
            Class numberUtil = Class.forName("com.lijiankun24.shadowlayout.NumberUtil");
            Method sub = numberUtil.getMethod("sub", double.class, double.class);
            Object obj = numberUtil.getConstructor().newInstance();
            int invoke = (int) sub.invoke(obj,2.0,1.0);
            assertEquals(1,invoke);
        } catch (InstantiationException | InvocationTargetException |
                NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * test乘
     */
    @Test
    public void testMul(){
        try {
            Class numberUtil = Class.forName("com.wuhenzhizao.sku.utils.NumberUtil");
            Method mul = numberUtil.getMethod("mul", double.class, double.class);
            Object object = numberUtil.getConstructor().newInstance();
            int invoke = (int) mul.invoke(object, 1, 2);
            assertEquals(2,invoke);
        } catch (InstantiationException | InvocationTargetException |
                NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * test除
     */
    @Test
    public void testDiv(){
        try {
            Class numberUtil = Class.forName("com.wuhenzhizao.sku.utils.NumberUtil");
            Method div = numberUtil.getMethod("div", double.class, double.class);
            Object object = numberUtil.getConstructor().newInstance();
            int invoke = (int) div.invoke(object, 2, 2);
            assertEquals(1,invoke);
        } catch (InstantiationException | InvocationTargetException |
                NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


}